<?php
	require_once('databaseevent.class.php');
	require_once('configdatabase.class.php');
	require_once('databaseeventlist.class.php');
	require_once('useraccesscontrol.class.php');
	require_once('lib/formatters/markdown-smartypants.php');
	
	$userAccessControl = new UserAccessControl();
	$database = new ConfigDatabase();
	$eventList = new DatabaseEventList();
	$eventList->read($database->getConnection(), $userAccessControl->isMod());
	$numberOfEvents = $eventList->count();
?>
<html>
	<head>
		<title>Kalender</title>
		<link rel="stylesheet" type="text/css" href="style.css" />
	</head>
	<body>
		<h1>Das kommt auf uns zu:</h1>
		<?php if (0 === $numberOfEvents): ?>
			<p>Im Moment steht nichts an.</p>
		<?php else: ?>
			<table class="eventtable">
				<thead style="display: none;">
					<tr><th>Datum/Uhrzeit</th><th>Titel</th><th>Beschreibung</th></tr>
				</thead>
				<tbody>
				<?php foreach ($eventList as $event): ?>
					<tr class="vevent">
						<td class="date dtstart" title="<?php echo($event->getDateTime()->format('c')); ?>"><?php echo($event->getDateTime()->format('d.m.Y')); ?></td>
						<td class="summary"><?php echo(htmlentities($event->getTitle())); ?></td>
						<td class="description"><?php echo(Markdown_SmartyPants($event->getDescription())); ?></td>
					</tr>
				<?php endforeach; ?>
				</tbody>
			</table>
		<?php endif; ?>
		<div id="bottomlinks">
			<div id="rightbottomlinks">
				<a href="http://www.&auml;ugenblicke.de/" target="_blank"><img src="gfx/banner_88x31.png" /></a>
			</div>
			<a href="modmenu.php">Modmen&uuml;</a>
			<?php if ($userAccessControl->isMod()): ?>
			    | <a href="addevent.php">Event eintragen</a>
				| <a href="logout.php">Ausloggen</a>
			<?php else: ?>
			    | <a href="addevent.php">Event vorschlagen</a>
			<?php endif; ?>
			<br style="clear: both;" />
		</div>
	</body>
</html>